import StatusNav from '@/components/school/statusNav';
import {mapGetters} from "vuex";
import * as GroupApi from '@/api/school/groupinfo.js';
import diyJson from '@/config/diy.js';
import {BASE_CONFIG} from "@/config/app";
import SchoolGroup from '@/components/school/group';
import {isBlank} from "@/utils/util";
export const mixins =
    {
      computed: mapGetters(['uid', 'userInfo', 'shareInfo', 'schoolId']),
      components: {
        StatusNav,SchoolGroup
      },
      data() {
        return {
          themConfig: diyJson.commonStyle,
          tabCurrent: 0,
          groupComponentProperties: {
            "showTitle":false,
            "component": "schoolGroup",
            "text": "跑腿团活动",
            "type": "school_group",
            "active": false,
            "style": "schoolGroupStyle",
            "setStyle": {
              "text": "跑腿团活动",
              "jsonData": {
                "title": "跑腿团活动",
                "more": "更多",
                "pic": "",
                "titleType": "1",
                "button": "立即参与",
                "bgType": "1",
                "titleBgImg": "https://git-1304113371.cos.ap-nanjing.myqcloud.com/Snipaste_2024-09-14_19-06-58.png",
              },
              "pageMargin": 12,
              "buttonColor": "#cb6025",
              "progressColor": "#ea7724",
              "priceColor": "#ea7724",
              "borderRadius": 10,
              "timeColor": "rgba(254, 255, 255, 1)",
              "padding": 10,
              "backgroundColor": "rgba(255, 255, 255, 1)",
              "backgroundImage": "",
              "timeBgColor": "#ea7724"
            }
          },
          tabList: [{
            "name": "活动中",
            "value": 0
          },
            {
              "name": "活动结束",
              "value": 1
            }
          ],
          isReachBottom: false,
          loading: {
            status: 'nomore',
            loadingText: '加载中',
            loadmoreText: '点击加载更多',
          },
          groupInfos: [],
          dataPage: {
            nextId: undefined,
            hasNext: false,
            ext: undefined
          },
          searchParams: {
            state: 0,
          },
          statusNavProperties: { // 筛选条件
            title: "团活动列表",
            setStyle: diyJson.statusbar.setStyle,
            showLeft:true,
            showHome:true
          },
        };
      },

      onLoad: function (options) {

      },

      created() {
      },

      onPullDownRefresh() {
        uni.stopPullDownRefresh();
      },

      onShow() {
        this.getGroupList(
            {...this.searchParams, schoolId: this.schoolId});
      },
      mounted() {
        // this.$refs.formPopup.open();
      },

      methods: {

        getGroupList(params) {
          GroupApi.groupList(params).then(res => {
            this.groupInfos = res.data.records;
            this.dataPage.ext = res.data.ext;
            this.dataPage.hasNext = res.data.hasNext;
            if (res.data.nextId) {
              this.dataPage.nextId = res.data.nextId;
            }
          });
        },
        // 滚到底部
        scrolltolower() {
          this.isReachBottom = true;
          this.loading.status = 'nomore';
          if (this.dataPage.hasNext) {
            this.loading.status = 'loadmore';
          }
        },
        loadmore() {
          if (this.dataPage.hasNext) {
            this.loading.status = 'loading';
            GroupApi.groupList({
              ...this.searchParams,
              schoolId: this.schoolId,
              nextId: this.dataPage.nextId
            }).then(res => {
              res.data.records.forEach(item => {
                this.groupInfos.push(item)
              })
              this.loading.status = 'loadmore';

              this.dataPage.ext = res.data.ext;
              this.dataPage.hasNext = res.data.hasNext;
              if (res.data.nextId) {
                this.dataPage.nextId = res.data.nextId;
              }
            });
          }
        },

        // 状态切换
        tabListChange(item) {
          // console.log('tabListChange',index)
          this.searchParams.state = item.value
          this.loading.status = 'nomore';
          this.getGroupList({...this.searchParams, schoolId: this.schoolId});
        },

        copyLick() {

          uni.setClipboardData({
            data: BASE_CONFIG.H5WebHost
                + '/pages/school/group-detail/index?params='
                + encodeURIComponent(JSON.stringify(this.urlParams)),
            success: function () {
              uni.showToast({
                title: '参团链接已复制',
                icon: 'success',
                duration: 2000
              });
            }
          });
        },

        clickBtn() {
          if ((isBlank(this.userInfo.phone) || isBlank(this.schoolId))){
            uni.showToast({
              title: '需要先注册信息......',
              duration: 1000,
              icon: 'none'
            });
            setTimeout(() => {
              uni.navigateTo({
                url: '/pages/users/user_info/index',
              })
            }, 500)
          }else {
            uni.navigateTo({url: '/pages/users/my-group/add/index'});
          }
        },

      },
      onReachBottom() {
        this.scrolltolower();
      }
    }
